﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.InterceptionExtension;
using SpectrumAnalyser.Services.ExpertiseResultStorageService.Services;
using SpectrumAnalyser.Services.ExpertiseResultStorageServiceContracts;

namespace SpectrumAnalyser.Services.ExpertiseResultStorageService
{
    public class ExpertiseResultStorageServiceModule
    {
        private readonly IUnityContainer _unityContainer;

         public ExpertiseResultStorageServiceModule(IUnityContainer unityContainer)
         {
             _unityContainer = unityContainer;
         }


         public void RegisterServices()
         {
             foreach (var type in ServiceTypes())
             {
                 _unityContainer.RegisterType(type.Key, type.Value);
                 _unityContainer.Configure<Interception>()
                               .SetDefaultInterceptorFor(type.Key, new TransparentProxyInterceptor());
             }
         }

         private IDictionary<Type, Type> ServiceTypes()
         {
             return new Dictionary<Type, Type>
                {
                    {typeof (IExpertiseStorageServiceContract), typeof (ExpertiseStorageService)}
                };
         }
    }
}